import { ref } from "vue";
import { defineStore } from "pinia";
import { getLoginUserAPi } from "@/api/login.js";

const useUserStore = defineStore("user", () => {
  const userInfo = ref(null);

  function initUserInfo() {
    !userInfo.value &&
      getLoginUserAPi().then(response => {
        userInfo.value = response.data;
      });
  }
  function setUserInfo(data) {
    userInfo.value = data;
  }
  function getUserInfo() {
    return userInfo.value;
  }
  initUserInfo();

  return { userInfo, setUserInfo, getUserInfo };
});
export default useUserStore;
